﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package pixelShader {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import __AS3__.vec.*;
    import flash.filters.*;
    import pbjAS.params.*;
    import pbjAS.regs.*;
    import pbjAS.*;
    import pbjAS.ops.*;

    public class Processor {

        private static var sync:Boolean = false;
        private static var shaderJob:ShaderJob;
        private static var shaderFilters:Vector.<ShaderFilter> = new Vector.<ShaderFilter>(5, true);
;
        private static var _instance:Processor;

        private var imgRect:Rectangle;
        private var rect:Rectangle;
        private var filterRect:Rectangle;
        private var mpt:Point;
        private var arc:int;
        private var m_highlightFilterPassCount:int = 0;
        private var bProcess:int = 0;
        private var index:int = 0;
        private var highlit:Boolean = false;
        private var animCtr:int = 1;
        private var walkingFrames:int = 220;
        private var pausedFrames:int = 5;
        private var totalFrames:int = 12;
        private var walkStyle:int = 0;
        private var m_scaler:Number = 1;
        private var loc:Point;
        private var dest:Point;

        public function Processor(){
            this.filterRect = new Rectangle();
            this.mpt = new Point();
            this.arc = int((Math.random() * 360));
            this.loc = new Point();
            this.dest = new Point();
            super();
            this.initShaderFilter();
        }
        public static function get instance():Processor{
            if (!_instance){
                _instance = new (Processor)();
            };
            return (_instance);
        }
        private static function onShaderComplete(_arg1:ShaderEvent):void{
            sync = false;
        }

        public function doShaderJob(_arg1:BitmapData, _arg2:BitmapData):BitmapData{
            var _local3:ShaderFilter = shaderFilters[0];
            var _local4:BitmapData = new BitmapData(_arg1.width, _arg1.height, true, 4294967040);
            _local3.shader.data.texture.input = _arg2;
            _local3.shader.data.trash.input = _arg2;
            _local3.shader.data.map.input = _arg1;
            new ShaderJob(_local3.shader, _local4).start(true);
            return (_local4);
        }
        private function initShaderFilter():void{
            var _local1:ShaderFilter = new ShaderFilter();
            var _local2:PBJ = new PBJ();
            _local2.version = 1.1;
            _local2.name = "PixelMapper";
            _local2.parameters = [new PBJParam("_OutCoord", new Parameter(PBJType.TFloat2, false, new RFloat(0, [PBJChannel.R, PBJChannel.G]))), new PBJParam("constants", new Parameter(PBJType.TFloat4, false, new RFloat(3))), new PBJParam("constants2", new Parameter(PBJType.TFloat4, false, new RFloat(5))), new PBJParam("trash", new Texture(4, 0)), new PBJParam("texture", new Texture(4, 1)), new PBJParam("map", new Texture(4, 2)), new PBJParam("result", new Parameter(PBJType.TFloat4, true, new RFloat(1)))];
            _local2.code = [new OpSampleNearest(new RFloat(2), new RFloat(0, [PBJChannel.R, PBJChannel.G]), 2), new OpMul(new RFloat(2, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(3, [PBJChannel.B, PBJChannel.B, PBJChannel.B])), new OpEqual(new RFloat(2, [PBJChannel.R]), new RFloat(3, [PBJChannel.A])), new OpMov(new RInt(0, [PBJChannel.G]), new RInt(0, [PBJChannel.R])), new OpEqual(new RFloat(2, [PBJChannel.G]), new RFloat(3, [PBJChannel.A])), new OpMov(new RInt(0, [PBJChannel.B]), new RInt(0, [PBJChannel.R])), new OpLogicalAnd(new RInt(0, [PBJChannel.G]), new RInt(0, [PBJChannel.B])), new OpIf(new RInt(0, [PBJChannel.R])), new OpMov(new RFloat(1), new RFloat(3, [PBJChannel.A, PBJChannel.A, PBJChannel.A, PBJChannel.A])), new OpElse(), new OpSampleLinear(new RFloat(1), new RFloat(2, [PBJChannel.R, PBJChannel.G]), 1), new OpEndIf(), new OpMov(new RFloat(4, [PBJChannel.R]), new RFloat(2, [PBJChannel.B])), new OpMod(new RFloat(4, [PBJChannel.R]), new RFloat(3, [PBJChannel.R])), new OpDiv(new RFloat(4, [PBJChannel.R]), new RFloat(3, [PBJChannel.G])), new OpLessThan(new RFloat(4, [PBJChannel.R]), new RFloat(5, [PBJChannel.B])), new OpIf(new RInt(0, [PBJChannel.R])), new OpMul(new RFloat(1, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(4, [PBJChannel.R, PBJChannel.R, PBJChannel.R])), new OpMul(new RFloat(1, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(5, [PBJChannel.A, PBJChannel.A, PBJChannel.A])), new OpElse(), new OpSub(new RFloat(4, [PBJChannel.R]), new RFloat(5, [PBJChannel.B])), new OpMov(new RFloat(4, [PBJChannel.G, PBJChannel.B, PBJChannel.A]), new RFloat(5, [PBJChannel.G, PBJChannel.G, PBJChannel.G])), new OpSub(new RFloat(4, [PBJChannel.A]), new RFloat(4, [PBJChannel.R])), new OpMov(new RFloat(4, [PBJChannel.R]), new RFloat(5, [PBJChannel.G])), new OpSub(new RFloat(4, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(1, [PBJChannel.R, PBJChannel.G, PBJChannel.B])), new OpMul(new RFloat(4, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(4, [PBJChannel.A, PBJChannel.A, PBJChannel.A])), new OpMov(new RFloat(1, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(5, [PBJChannel.G, PBJChannel.G, PBJChannel.G])), new OpSub(new RFloat(1, [PBJChannel.R, PBJChannel.G, PBJChannel.B]), new RFloat(4, [PBJChannel.R, PBJChannel.G, PBJChannel.B])), new OpEndIf(), new OpMov(new RFloat(4, [PBJChannel.R]), new RFloat(2, [PBJChannel.B])), new OpDiv(new RFloat(4, [PBJChannel.R]), new RFloat(3, [PBJChannel.R])), new OpFloor(new RFloat(4, [PBJChannel.G]), new RFloat(4, [PBJChannel.R])), new OpDiv(new RFloat(4, [PBJChannel.G]), new RFloat(3, [PBJChannel.G])), new OpMov(new RFloat(1, [PBJChannel.A]), new RFloat(4, [PBJChannel.G]))];
            var _local3:ByteArray = PBJAssembler.assemble(_local2);
            var _local4:Shader = new Shader(_local3);
            _local1.shader = _local4;
            _local1.shader.data.constants.value = [16, 15, 0xFF, 0];
            _local1.shader.data.constants2.value = [-1, 1, 0.5, 2];
            shaderFilters[0] = _local1;
        }

    }
}//package pixelShader 
